//
//  FlyBlurImageView.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2017/11/3.
//  Copyright © 2017年 lifayu. All rights reserved.
//

#import "FlyBlurImageView.h"
@interface FlyBlurImageView()

@property (strong, nonatomic) UIVisualEffectView *visualEffectView;

@end

@implementation FlyBlurImageView
- (void)layoutSubviews
{
    [super layoutSubviews];
    if(self.visualEffectView)
    {
        self.visualEffectView.frame = self.bounds;
    }
}

- (void)enableBlurImage:(BOOL)enable
{
    if(enable)
    {
        if(!self.visualEffectView)
        {
            UIBlurEffect *blurEffrct =[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
            
            self.visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffrct];
            self.visualEffectView.alpha = 0.95;
            [self addSubview:self.visualEffectView];
        }
    }
    else
    {
        if(self.visualEffectView)
        {
            [self.visualEffectView removeFromSuperview];
            self.visualEffectView = nil;
        }
    }
    [self layoutIfNeeded];
}

- (void)setBlurEffectStyle:(UIBlurEffectStyle)style
{
    if(self.visualEffectView)
    {
        UIBlurEffect *blurEffrct =[UIBlurEffect effectWithStyle:style];
        [self.visualEffectView setEffect:blurEffrct];
    }
    [self layoutIfNeeded];
}

- (void)enableBlurImage:(BOOL)enable blurEffectStyle:(UIBlurEffectStyle)style
{
    [self enableBlurImage:enable];
    [self setBlurEffectStyle:style];
    [self layoutIfNeeded];
}

@end
